package com.xjrsoft.module.customerTwo.AppManage.test.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.customerTwo.AppManage.test.dto.ErpFinanceexpenditureDto;
import com.xjrsoft.module.customerTwo.AppManage.test.dto.SaveErpFinanceexpenditureFormDataDto;
import com.xjrsoft.module.customerTwo.AppManage.test.vo.ErpFinanceexpenditureVo;
import com.xjrsoft.module.customerTwo.AppManage.test.vo.ErpFinanceexpenditureListVo;
import com.xjrsoft.module.customerTwo.AppManage.test.dto.ErpFinanceexpenditureListDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customerTwo.AppManage.test.entity.ErpFinanceexpenditure;
import com.xjrsoft.module.customerTwo.AppManage.test.vo.ErpFinanceexpenditureVo;
import com.xjrsoft.module.customerTwo.AppManage.test.service.IErpFinanceexpenditureService;

/**
 * 财政支出表 控制器
 *
 * @author dong
 * @since 2023-12-07
 */
@RestController
@AllArgsConstructor
@RequestMapping("/test")
@Api(value = "测试", tags = "测试接口")
public class ErpFinanceexpenditureController {


	private final IErpFinanceexpenditureService erpFinanceexpenditureService;


	/**
	 * 详情 
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入erpFinanceexpenditure")
	@SaCheckPermission(value = {"Test:view", "Test:modify"}, mode = SaMode.OR)
	public Response<ErpFinanceexpenditureVo> getFormData(@PathVariable String id) {
		// 主表数据
		ErpFinanceexpenditure erpFinanceexpenditure = erpFinanceexpenditureService.getById(id);
		ErpFinanceexpenditureVo erpFinanceexpenditureVo = BeanUtil.copy(erpFinanceexpenditure, ErpFinanceexpenditureVo.class);
		return Response.ok(erpFinanceexpenditureVo);
	}

	/**
	 * 自定义分页 财政支出表
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入erpFinanceexpenditure")
		public Response<PageOutput<ErpFinanceexpenditureListVo>> getPageList(ErpFinanceexpenditureListDto listDto) {
		IPage<ErpFinanceexpenditure> page = erpFinanceexpenditureService.getPageList(listDto);
		List<ErpFinanceexpenditureListVo> records = BeanUtil.copyList(page.getRecords(), ErpFinanceexpenditureListVo.class);
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 财政支出表
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入erpFinanceexpenditure")
	@SaCheckPermission("Test:add")
	public Response save(@RequestBody SaveErpFinanceexpenditureFormDataDto formDto) {
		ErpFinanceexpenditureDto erpFinanceexpenditureDto = formDto.getErpFinanceexpenditureDto();
		ErpFinanceexpenditure erpFinanceexpenditure = BeanUtil.copy(erpFinanceexpenditureDto, ErpFinanceexpenditure.class);
		boolean isSuccess = erpFinanceexpenditureService.addErpFinanceexpenditure(erpFinanceexpenditure);
		return Response.status(isSuccess);
	}

	/**
	 * 修改 财政支出表
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入erpFinanceexpenditure")
	@SaCheckPermission("Test:modify")
	public Response update(@PathVariable String id, @RequestBody SaveErpFinanceexpenditureFormDataDto formDto) {
		ErpFinanceexpenditureDto erpFinanceexpenditureDto = formDto.getErpFinanceexpenditureDto();
		ErpFinanceexpenditure erpFinanceexpenditure = BeanUtil.copy(erpFinanceexpenditureDto, ErpFinanceexpenditure.class);
		return Response.status(erpFinanceexpenditureService.updateErpFinanceexpenditure(id, erpFinanceexpenditure));
	}



	/**
	 * 删除 财政支出表
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	@SaCheckPermission(value = {"Test:batchDelete", "Test:delete"}, mode = SaMode.OR)
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(erpFinanceexpenditureService.delete(ids));
	}


}
